1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
import ChapterSelector from "@/components/manga/chapters";
import HamburgerMenu from "@/components/manga/mobile/hamburgerMenu";
import TopSection from "@/components/manga/info/topSection";
import Footer from "@/components/shared/footer";
import Head from "next/head";
import { useEffect, useState } from "react";
import { setCookie } from "nookies";
import { getServerSession } from "next-auth";
import { authOptions } from "../../api/auth/[...nextauth]";
import getAnifyInfo from "@/lib/anify/info";
import { NewNavbar } from "@/components/shared/NavBar";
export default function Manga({ info, userManga }) {
const [domainUrl, setDomainUrl] = useState("");
const [firstEp, setFirstEp] = useState();
const chaptersData = info.chapters.data;
useEffect(() => {
setDomainUrl(window.location.origin);
}, []);
return (
<>
<Head>
<title>
{info
? `Manga - ${
info.title.romaji || info.title.english || info.title.native
}`
: "Getting Info..."}
</title>
<meta name="twitter:card" content="summary_large_image" />
<meta
name="twitter:title"
content={`Moopa - ${info.title.romaji || info.title.english}`}
/>
<meta
name="twitter:description"
content={`${info.description?.slice(0, 180)}...`}
/>
<meta
name="twitter:image"
content={`${domainUrl}/api/og?title=${
info.title.romaji || info.title.english
}&image=${info.bannerImage || info.coverImage}`}
/>
<meta
name="title"
data-title-romaji={info?.title?.romaji}
data-title-english={info?.title?.english}
data-title-native={info?.title?.native}
/>
</Head>
<div className="min-h-screen w-screen flex flex-col items-center relative">
<HamburgerMenu />
<NewNavbar info={info} manga={true} />
<div className="flex flex-col w-screen items-center gap-5 md:gap-10 py-10 pt-nav">
<div className="flex-center w-full relative z-30">
<TopSection info={info} firstEp={firstEp} setCookie={setCookie} />
<>
<div className="absolute hidden md:block z-20 bottom-0 h-1/2 w-full bg-secondary" />
<div className="absolute hidden md:block z-20 top-0 h-1/2 w-full bg-transparent" />
</>
</div>
<div className="w-[90%] xl:w-[70%] min-h-[35vh] z-40">
{chaptersData.length > 0 ? (
<ChapterSelector
chaptersData={chaptersData}
data={info}
setFirstEp={setFirstEp}
setCookie={setCookie}
userManga={userManga}
/>
) : (
<p>No Chapter Available :(</p>
)}
</div>
</div>
<Footer />
</div>
</>
);
}
export async function getServerSideProps(context) {
const session = await getServerSession(context.req, context.res, authOptions);
const accessToken = session?.user?.token || null;
const { id } = context.query;
const key = process.env.API_KEY;
const data = await getAnifyInfo(id, key);
let userManga = null;
if (session) {
const response = await fetch("https://graphql.anilist.co/", {
method: "POST",
headers: {
"Content-Type": "application/json",
...(accessToken && { Authorization: `Bearer ${accessToken}` }),
},
body: JSON.stringify({
query: `
query ($id: Int) {
Media (id: $id) {
mediaListEntry {
status
progress
progressVolumes
status
}
id
idMal
title {
romaji
english
native
}
}
}
`,
variables: {
id: parseInt(id),
},
}),
});
const data = await response.json();
const user = data?.data?.Media?.mediaListEntry;
if (user) {
userManga = user;
}
}
if (!data?.chapters) {
return {
notFound: true,
};
}
return {
props: {
info: data,
userManga,
},
};
}
|